﻿using System;
using Company.IO.Interfaces;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SearchOption = System.IO.SearchOption;

namespace Company.System.IO.IntegrationTests
{
    public partial class DirectoryTest : TestBase<IDirectory>
    {
        private const string _SGetDirectoriesMethodName = "GetDirectories";

        [TestMethod]
        public void GetDirectories_PathValid_Directories()
        {
            //Arrange
            string path = SLocalPath;
            string[] expected = global::System.IO.Directory.GetDirectories(path);

            //Act
            string[] actual = Directory.GetDirectories(path);

            //Assert
            Assert.AreEqual(expected.Length, actual.Length);
        }

        [TestMethod]
        public void GetDirectories_PathValidSearchPatternValid_Files()
        {
            //Arrange
            string path = SLocalPath;
            string searchPattern = string.Empty;
            string[] expected = global::System.IO.Directory.GetDirectories(path, searchPattern);

            //Act
            string[] actual = Directory.GetDirectories(path, searchPattern);

            //Assert
            Assert.AreEqual(expected.Length, actual.Length);
        }

        [TestMethod]
        public void GetDirectories_PathValidSearchPatternValidSearchOptionAllDirectories_Files()
        {
            //Arrange
            string path = SLocalPath;
            string searchPattern = string.Empty;
            string[] expected = global::System.IO.Directory.GetDirectories(path, searchPattern,
                                                                           SearchOption.AllDirectories);

            //Act
            string[] actual = Directory.GetDirectories(path, searchPattern,
                                                       Company.IO.Interfaces.SearchOption.AllDirectories);

            //Assert
            Assert.AreEqual(expected.Length, actual.Length);
        }

        [TestMethod]
        public void GetDirectories_PathNull_ArgumentNullException()
        {
            PathNull_ArgumentNullException(_SGetDirectoriesMethodName);
        }

        [TestMethod]
        public void GetDirectories_PathEmpty_ArgumentException()
        {
            PathEmpty_ArgumentException(_SGetDirectoriesMethodName);
        }

        [TestMethod]
        public void GetDirectories_PathNullSearchPatternNull_ArgumentNullException()
        {
            //Arrange
            Type[] parameterTypes = GetTypeArray<string, string>();
            object[] parameterValues = GetValueArray(SStringNull, SStringNull);
            //Act
            ExpectException<ArgumentNullException>(_SGetDirectoriesMethodName, parameterTypes, parameterValues);
            //Assert
        }

        [TestMethod]
        public void GetDirectories_PathNullSearchPatternNullSearchOptionAllDirectories_ArgumentNullException()
        {
            //Arrange
            Type[] parameterTypes = GetTypeArray<string, string, Company.IO.Interfaces.SearchOption>();
            object[] parameterValues = GetValueArray(SStringNull, SStringNull,
                                                     Company.IO.Interfaces.SearchOption.AllDirectories);
            //Act
            ExpectException<ArgumentNullException>(_SGetDirectoriesMethodName, parameterTypes, parameterValues);
            //Assert
        }

        [TestMethod]
        public void GetDirectories_PathValidSearchPatternNull_ArgumentNullException()
        {
            //Arrange
            Type[] parameterTypes = GetTypeArray<string, string>();
            object[] parameterValues = GetValueArray(_SGetDirectoriesMethodName, SStringNull);
            //Act
            ExpectException<ArgumentNullException>(_SGetDirectoriesMethodName, parameterTypes, parameterValues);
            //Assert
        }

        [TestMethod]
        public void GetDirectories_PathValidSearchPatternNullSearchOptionAllDirectories_ArgumentNullException()
        {
            //Arrange
            Type[] parameterTypes = GetTypeArray<string, string, Company.IO.Interfaces.SearchOption>();
            object[] parameterValues = GetValueArray(_SGetDirectoriesMethodName, SStringNull,
                                                     Company.IO.Interfaces.SearchOption.AllDirectories);
            //Act
            ExpectException<ArgumentNullException>(_SGetDirectoriesMethodName, parameterTypes, parameterValues);
            //Assert
        }
    }
}